package com.spzx.order.configure;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class DelayedMqConfig {

    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";
    //创建延迟队列
    @Bean
    public Queue createDelayQueue(){
        return new Queue(queue_delay_1,true);
    }
    //创建延迟交换机
    @Bean
    public CustomExchange createDelayExchange(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(exchange_delay, "x-delayed-message", true, false, args);

    }
    //创建绑定关系
    @Bean
    public Binding createDelayBinding(){
        return BindingBuilder.bind(createDelayQueue()).to(createDelayExchange()).with(routing_delay).noargs();
    }
}
